﻿<%@ WebHandler Language="C#" Class="SIPO.Web.AjaxHandler.Loaddata.getregistrationbynpwp" %>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using SIPO.Library.DataAccess.Transaction;
using SIPO.Library.DomainObject.Transaction;
using SIPO.Library.Enum;
using SIPO.Web.Support;
using Newtonsoft.Json.Linq;
using System.Text;

namespace SIPO.Web.AjaxHandler.Loaddata
{
    public class getregistrationbynpwp : SIPO.Web.BaseHandler
    {
        recRegistrationRepo recRegistrationDal = new recRegistrationRepo(ConfigurationManager.ConnectionStrings["SIPOConn"].ConnectionString);
        public override void ProcessRequest(HttpContext context)
        {
            base.ProcessRequest(context);
            string npwp = context.Request.Params["npwp"].ToString().Trim();
            string debtorName = string.Empty;
            string address1 = string.Empty;
            string address2 = string.Empty;
            string address3 = string.Empty;
            string zipcode = string.Empty;
            string phone = string.Empty;
            string fax = string.Empty;
            string email = string.Empty;
            string website = string.Empty;
            int? regionId = 0;
            int? cityId = 0;
            string regionName = string.Empty;
            string cityName = string.Empty;
            string regionCode = string.Empty;
            string cityCode = string.Empty;
            int isindividual = 0;
            string emisionValue = string.Empty;
            int? jenisemisi = 0;
            recRegistration recRegistration = new recRegistration();
            recRegistration = recRegistrationDal.GetByNPWP(npwp);
            if (recRegistration != null)
            {
                debtorName = recRegistration.PreDebtorName;
                address1 = recRegistration.Address1;
                address2 = recRegistration.Address2;
                address3 = recRegistration.Address3;
                zipcode = recRegistration.ZipCode;
                phone = recRegistration.Phone;
                fax = recRegistration.Fax;
                email = recRegistration.Email;
                website = recRegistration.Website;
                regionId = recRegistration.RegionID;
                cityId = recRegistration.CityID;
                regionName = recRegistration.recRegion.RegionName;
                cityName = recRegistration.recCity.CityName;
                regionCode = recRegistration.recRegion.RegionCode;
                cityCode = recRegistration.recCity.CityCode;
                isindividual = recRegistration.IsIndividual == false ? 0 : 1;
                if (recRegistration.recSectorRegistration.EmisionValue.ToString().Contains('.'))
                    emisionValue = recRegistration.recSectorRegistration.EmisionValue.ToString().Substring(0, recRegistration.recSectorRegistration.EmisionValue.ToString().IndexOf('.'));
                else if (recRegistration.recSectorRegistration.EmisionValue.ToString().Contains(','))
                    emisionValue = recRegistration.recSectorRegistration.EmisionValue.ToString().Substring(0, recRegistration.recSectorRegistration.EmisionValue.ToString().IndexOf(','));
                jenisemisi = recRegistration.recSectorRegistration.EmisionTypeID;
            }
            StringBuilder sbProject = new StringBuilder();
            sbProject.Append("{");
            sbProject.AppendFormat("  {0}DebtorName{0}:{0}{1}{0}", "\"", debtorName);
            sbProject.Append(",");
            sbProject.AppendFormat("  {0}Address1{0}:{0}{1}{0}", "\"", address1);
            sbProject.Append(",");
            sbProject.AppendFormat("  {0}Address2{0}:{0}{1}{0}", "\"", address2);
            sbProject.Append(",");
            sbProject.AppendFormat("  {0}Address2{0}:{0}{1}{0}", "\"", address2);
            sbProject.Append(",");
            sbProject.AppendFormat("  {0}Address3{0}:{0}{1}{0}", "\"", address3);
            sbProject.Append(",");
            sbProject.AppendFormat("  {0}ZipCode{0}:{0}{1}{0}", "\"", zipcode);
            sbProject.Append(",");
            sbProject.AppendFormat("  {0}Phone{0}:{0}{1}{0}", "\"", phone);
            sbProject.Append(",");
            sbProject.AppendFormat("  {0}Fax{0}:{0}{1}{0}", "\"", fax);
            sbProject.Append(",");
            sbProject.AppendFormat("  {0}Email{0}:{0}{1}{0}", "\"", email);
            sbProject.Append(",");
            sbProject.AppendFormat("  {0}Website{0}:{0}{1}{0}", "\"", website);
            sbProject.Append(",");
            sbProject.AppendFormat("  {0}RegionId{0}:{0}{1}{0}", "\"", regionId);
            sbProject.Append(",");
            sbProject.AppendFormat("  {0}CityId{0}:{0}{1}{0}", "\"", cityId);
            sbProject.Append(",");
            sbProject.AppendFormat("  {0}RegionName{0}:{0}{1}{0}", "\"", regionName);
            sbProject.Append(",");
            sbProject.AppendFormat("  {0}CityName{0}:{0}{1}{0}", "\"", cityName);
            sbProject.Append(",");
            sbProject.AppendFormat("  {0}CityCode{0}:{0}{1}{0}", "\"", cityCode);
            sbProject.Append(",");
            sbProject.AppendFormat("  {0}RegionCode{0}:{0}{1}{0}", "\"", regionCode);
            sbProject.Append(",");
            sbProject.AppendFormat("  {0}IsIndividual{0}:{0}{1}{0}", "\"", isindividual);
            sbProject.Append(",");
            sbProject.AppendFormat("  {0}EmisionValue{0}:{0}{1}{0}", "\"", emisionValue);
            sbProject.Append(",");
            sbProject.AppendFormat("  {0}EmisionType{0}:{0}{1}{0}", "\"", jenisemisi);
            sbProject.Append("}");

            context.Response.Write(sbProject.ToString());
        }
        public override bool IsReusable
        {
            get
            {
                return false;
            }
        }

    }
}